package com.youdianda.controller.ydd;

import com.youdianda.dto.YddUserPageDTO;
import com.youdianda.entity.YddUser;
import com.youdianda.result.PageResult;
import com.youdianda.result.Result;
import com.youdianda.service.YddUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;


/**
 * 会员管理/5.1用户管理
 */
@RestController
@RequestMapping("/ydd_user")
public class YddUserController {

    @Autowired
    private YddUserService yddUserService;

    /**
     * 用户详情
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public Result roeInfo(String id){
        YddUser user = yddUserService.getById(id);
        return Result.success(user);
    }

    /**
     * 用户列表
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public Result<PageResult> list(YddUserPageDTO dto){
        Result<PageResult> list = yddUserService.list(dto);
        return list;
    }

    /**
     * 用户添加
     * @param yddUser
     * @return
     */
    @PostMapping("/add")
    @Transactional
    public Result addUser(@RequestBody YddUser yddUser){
        yddUserService.save(yddUser);
        return Result.success();
    }

    /**
     * 用户删除
     * @param id
     * @return
     */
    @GetMapping("/del")
    public Result deleteUser(String id){
        yddUserService.removeById(id);
        return Result.success();
    }

    /**
     * 用户修改
     * @param yddUser
     * @return
     */
    @PostMapping("/update")
    @Transactional
    public Result updateUser(@RequestBody YddUser yddUser){
        yddUserService.updateUser(yddUser);
        return Result.success();
    }
}
